class ListNode {
      int val;
      ListNode next;
     ListNode() {}
      ListNode(int val) { this.val = val; }
      ListNode(int val, ListNode next) { this.val = val; this.next = next; }
}
public class demo1 {
    public ListNode reverseList(ListNode head) {
         //当head节点为空时或head下一节点为空时返回
        if(head==null||head.next==null)return head;
        ListNode nhead=reverseList(head.next);//逆序后的头节点
        head.next.next=head;
        head.next=null;
        return nhead;
    }
}
